package com.module.product.dao;

import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import base.dao.GenericHibernateDao;
import base.util.EntityUtil;

import com.module.product.vo.AttrValueTemporarySyn;
import com.module.product.vo.SynStatus;
/**
*
* 商品属性值同步dao类
*
* @author  张景洋
*/
public class AttrValueTemporarySynDao extends  GenericHibernateDao<AttrValueTemporarySyn, Long>{

	private static final AttrValueTemporarySynDao instance = new AttrValueTemporarySynDao();
	
	private AttrValueTemporarySynDao(){}
	
	public synchronized static AttrValueTemporarySynDao getInstance() {
		return instance;
	}
	SynStatusDao synStatusDao =  SynStatusDao.getInstance();
	/**
	 * 根据产品ID列表获取相应属性值列表
	 * @param session
	 * @param productIds
	 * @return
	 */
    public List<AttrValueTemporarySyn> list(Session session,String orgid,String productIds){
    	String tableName = EntityUtil.getTableName(AttrValueTemporarySyn.class);
    	Long syscId = synStatusDao.getIdByorgIdAndTableName(session,orgid,tableName);
    	
        List<AttrValueTemporarySyn> list = null ;
        Query query = session.createQuery("from AttrValueTemporarySyn o  where o.issysc ='1' and o.iSyscId > ? and o.productId in ( "+productIds+" ) order by o.iSyscId");
        query.setParameter(0,syscId);
        list = query.list();
        if(list != null && list.size()>0){
        	//获取同步数据后，保存同步记录到synStatus
        	SynStatus synStatus =  new SynStatus();
        	synStatus.setiSyscId(list.get(list.size()-1).getiSyscId());
        	synStatus.setOrgId(orgid);
        	synStatus.setSyscTime(new Date());
        	synStatus.setTableName(tableName);
        	synStatusDao.save(session, synStatus);
        }
        return list;
    }
    


    
    
    

    
  
    
}
